package biz.noorlander.bat.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@NamedQueries({
	@NamedQuery(name="MerchantSession.fetchWithServices", query="select m from MerchantSession m left join fetch m.merchantServices where m = :session")
})
public class MerchantSession {

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer id;

	@ManyToOne(cascade=CascadeType.ALL)
	private Player customer;
	
	@Temporal(TemporalType.TIMESTAMP)
	private Date sessionStart = new Date();
	
	@Temporal(TemporalType.TIMESTAMP)
	private Date sessionEnd;

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinColumn( name = "MERCHANTSESSION_ID", nullable = false)
	List<MerchantService> merchantServices = new ArrayList<MerchantService>();
	
	public List<MerchantService> getMerchantServices() {
		return merchantServices;
	}

	private void setMerchantServices(List<MerchantService> merchantServices) {
		this.merchantServices = merchantServices;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Player getCustomer() {
		return customer;
	}

	public void setCustomer(Player customer) {
		this.customer = customer;
	}

	public Date getSessionEnd() {
		return sessionEnd;
	}

	public void setSessionEnd(Date sessionEnd) {
		this.sessionEnd = sessionEnd;
	}

	public Date getSessionStart() {
		return sessionStart;
	}
}
